import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String u = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=659041774760.apps.googleusercontent.com&redirect_uri=http://www.acsedu.hk/tqb_news/oauth2callback.action&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile";
		String url = "";
		try {
			url = java.net.URLEncoder.encode(u,"utf-8");
			System.out.println("url: "+url);
		} catch (UnsupportedEncodingException e1) {
			System.out.println("UnsupportedEncodingException");
			e1.printStackTrace();
			return;
		}
		
		URL urlRequest = null;
		HttpURLConnection url_con = null;
		StringBuilder tempStr;
		try {
			urlRequest = new URL(url);
			url_con = (HttpURLConnection)urlRequest.openConnection();
			url_con.setRequestMethod("GET");
            url_con.setDoOutput(true);

            // url_con.getOutputStream().write(param.getBytes());
            url_con.getOutputStream().flush();
            url_con.getOutputStream().close();
            
            InputStream in = url_con.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(in));
            tempStr = new StringBuilder();
            while (rd.read() != -1) {
                tempStr.append(rd.readLine());
            }
            System.out.println("response: "+tempStr);
            
		} catch (MalformedURLException e) {
			System.out.println("MalformedURLException");
			e.printStackTrace();
			return;
		}catch (IOException e) {
			System.out.println("IOException");
			e.printStackTrace();
			return;
		}
		

	}

}
